home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.c
- Subject: Re: operator % - compiler error
- Date: 21 Mar 96 15:51:18 GMT
- Organization: Clemson University
- Message-ID: <mjs.827423478@hubcap>
- References: <4ini8g$i1u@spanky.pls.ov.com> <4iro6q$2e9@nntp.interaccess.com>
- NNTP-Posting-Host: hubcap.clemson.edu
- X-Newsreader: NN version 6.5.0 #1
-
- brianmcg@interaccess.com (Brian V. McGroarty) writes:
-
- >This is something I've wondered about. Why isn't the mod operator defined
- >for floating point math? It can be implemented easily enough via something
- >like:
-
- >#define MOD( base, op ) ( (base) - ( (base) / (op) ) * (op) )
-
- You need to cast the quotient to int before remultiplying. Otherwise
- the result will be zero (up to rounding error).
-
- >..so it does have validity, however the efficiency of using the remainder
- >on FPUs returning the remainder along with the result of a divide is lost
- >-- a spurious subtraction and multiplication are added.
-
- FPUs as a rule don't return an integer quotient and remainder, they
- return a floating point result.
-
- If you want the floating-point remainder, use the fmod() function
- declared in math.h.
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-